(function() {
    Nokia.MiniView = Nokia.Widget.extend({
        initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

            instance._create();

			instance.setContent(instance.options.content);

			instance.registerData("miniview");

			instance.fireCallback('create');
        },

		setContent: function(value) {
			var instance = this;

			if (value) {
				instance.content = value;
				instance.element.html( instance.getContent() );
			}
		},

		getContent: function() {
			var instance = this;

			return Nokia.dom.parseHTML(instance.content);
		},

		show: function() {
			var instance = this;

			instance.fireCallback('show');

			instance.element.show();
		},

		hide: function() {
			var instance = this;

			instance.fireCallback('hide');

			instance.element.hide();
		},

		_create: function() {
			var instance = this;
			var options = instance.options;
			var element = instance.element;
			var Styles = instance.Styles;

			instance.element.addClass([
				Styles.miniview,
				Styles.widget,
				Styles.widgetContent,
				Styles.cornerAll
			].join(' '));

			if (options.style) {
				instance.element.css(options.style);
			}
		},

		Styles: {
			miniview: 'nokia-miniview',
			miniviewHybridImage: 'nokia-miniview-hybrid-image',
			miniviewHybridText: 'nokia-miniview-hybrid-text',
			miniviewLandscapeImage: 'nokia-miniview-landascape-image',
			miniviewMultipleImagesImage: 'nokia-miniview-multipleimages-image',
			miniviewHybridHorizontalImage: 'nokia-miniview-hybridhorizontal-image',
			miniviewHybridHorizontalText: 'nokia-miniview-hybridhorizontal-text',
			miniviewGridText: 'nokia-miniview-grid-text',
			miniviewGridImage: 'nokia-miniview-grid-image',
			miniviewGridRow: 'nokia-miniview-grid-row',
			uiClearFix: 'ui-helper-clearfix',
			widget: 'ui-widget',
			widgetContent: 'ui-widget-content'
		}
    });

    Nokia.MiniViewHybrid = Nokia.MiniView.extend({
    	initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

			instance.options.content = Nokia.dom.parseHTML(instance.options.content);

			instance.registerData("miniviewhybrid");

			instance.setContent(instance.options.content);

			instance.fireCallback('create');
        },

        getContent: function() {
			var instance = this;
			var options = instance.options;
			var Styles = instance.Styles;

			var wrapper = Nokia.dom.parseHTML('<div></div>');
			var image = Nokia.dom.parseHTML('<img class="' + [Styles.miniviewHybridImage].join(' ') + '" src="' + options.image + '" />');
			var text = Nokia.dom.parseHTML('<p class="' + [Styles.miniviewHybridText].join(' ') + '">' + options.text + '</p>');

			Nokia.dom.append(wrapper, image);
			Nokia.dom.append(wrapper, text);

			return Nokia.dom.parseHTML(wrapper.html());
		}
    });

    Nokia.MiniViewLandscapeImage = Nokia.MiniView.extend({
    	initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

			instance.options.content = Nokia.dom.parseHTML(instance.options.content);

			instance.registerData("miniviewlandscapeimage");

			instance.setContent(instance.options.content);

			instance.fireCallback('create');
        },

        getContent: function() {
			var instance = this;
			var options = instance.options;
			var Styles = instance.Styles;

			var wrapper = Nokia.dom.parseHTML('<div></div>');
			var image = Nokia.dom.parseHTML('<img class="' + [Styles.miniviewLandscapeImage].join(' ') + '" src="' + options.image + '" />');

			Nokia.dom.append(wrapper, image);

			return Nokia.dom.parseHTML(wrapper.html());
		}
    });

    Nokia.MiniViewMultipleImages = Nokia.MiniView.extend({
    	initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

			instance.options.content = Nokia.dom.parseHTML(instance.options.content);

			instance.registerData("miniviewmultipleimages");

			instance.setContent(instance.options.content);

			instance.fireCallback('create');
        },

        getContent: function() {
			var instance = this;
			var options = instance.options;
			var Styles = instance.Styles;
			var images = options.images;

			var wrapper = Nokia.dom.parseHTML('<div></div>');

			jQuery.each(images, function(i, img){
				var image = Nokia.dom.parseHTML('<img class="' + [Styles.miniviewMultipleImagesImage].join(' ') + '" src="' + img + '" />');

				Nokia.dom.append(wrapper, image);
			});

			return Nokia.dom.parseHTML(wrapper.html());
		}
    });

    Nokia.MiniViewHybridHorizontal = Nokia.MiniView.extend({
    	initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

			instance.options.content = Nokia.dom.parseHTML(instance.options.content);

			instance.registerData("miniviewhybridhorizontal");

			instance.setContent(instance.options.content);

			instance.fireCallback('create');
        },

        getContent: function() {
			var instance = this;
			var options = instance.options;
			var Styles = instance.Styles;

			var wrapper = Nokia.dom.parseHTML('<div></div>');
			var image = Nokia.dom.parseHTML('<img class="' + [Styles.miniviewHybridHorizontalImage].join(' ') + '" src="' + options.image + '" />');
			var text = Nokia.dom.parseHTML('<p class="' + [Styles.miniviewHybridHorizontalText].join(' ') + '">' + options.text + '</p>');

			Nokia.dom.append(wrapper, image);
			Nokia.dom.append(wrapper, text);

			return Nokia.dom.parseHTML(wrapper.html());
		}
    });

    Nokia.MiniViewGrid = Nokia.MiniView.extend({
    	initialize: function(options) {
            var instance = this;

			var defaults = {
				content: ''
            };

            instance.options = jQuery.extend(defaults, options);

            instance.element = jQuery( instance.options.element );

            instance._super.apply(instance, [instance.options]);

			instance.options.content = Nokia.dom.parseHTML(instance.options.content);

			instance.registerData("miniviewgrid");

			instance.setContent(instance.options.content);

			instance.fireCallback('create');
        },

        getContent: function() {
			var instance = this;
			var options = instance.options;
			var Styles = instance.Styles;
			var rows = options.rows;

			var wrapper = Nokia.dom.parseHTML('<div></div>');

			jQuery.each(rows, function(i, row) {
				var container = Nokia.dom.parseHTML('<div class="' + [Styles.uiClearFix, Styles.miniviewGridRow].join(' ') + '"></div>');
				var image = Nokia.dom.parseHTML('<img class="' + [Styles.miniviewGridImage].join(' ') + '" src="' + row.image + '" />');
				var text = Nokia.dom.parseHTML('<p class="' + [Styles.miniviewGridText].join(' ') + '">' + row.text + '</p>');

				Nokia.dom.append(container, image);
				Nokia.dom.append(container, text);

				Nokia.dom.append(wrapper, container);
			});

			return Nokia.dom.parseHTML(wrapper.html());
		}
    });
})();